package com.androidx.p013lv.invention.activity;

import android.view.View;
import androidx.recyclerview.widget.LinearLayoutManager;
import com.alibaba.android.arouter.launcher.ARouter;
import com.androidx.p013lv.base.Constance;
import com.androidx.p013lv.base.bean.AttentionContentBean;
import com.androidx.p013lv.base.bean.InventionThreeBean;
import com.androidx.p013lv.base.bean.StarBean;
import com.androidx.p013lv.base.bean.event.AttentionEvent;
import com.androidx.p013lv.base.http.BaseRes;
import com.androidx.p013lv.base.http.HttpUtils;
import com.androidx.p013lv.base.http.UrlManager;
import com.androidx.p013lv.base.http.callback.HttpCallback;
import com.androidx.p013lv.base.interfaces.Key;
import com.androidx.p013lv.base.listener.ItemClickListener;
import com.androidx.p013lv.base.p015ui.BaseActivity;
import com.androidx.p013lv.base.utils.NetUtil;
import com.androidx.p013lv.base.utils.ToastUtils;
import com.androidx.p013lv.invention.C1069R;
import com.androidx.p013lv.invention.HttpAttention;
import com.androidx.p013lv.invention.adapter.AdapterStar;
import com.androidx.p013lv.invention.databinding.ActivityStarBinding;
import com.gyf.immersionbar.ImmersionBar;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnRefreshLoadMoreListener;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

/* renamed from: com.androidx.lv.invention.activity.StarActivity */
public class StarActivity extends BaseActivity<ActivityStarBinding> implements ItemClickListener, OnRefreshLoadMoreListener {
    String HTTP_CANCEL_TAG = "cancelAttention";
    String HTTP_SAVE_TAG = "saveAttention";
    String HTTP_TAG = "queryContentMore";
    AdapterStar adapter;
    InventionThreeBean bean;
    HttpCallback<BaseRes<AttentionContentBean>> cancelHttp;
    int index;
    int lastId = 0;
    public String name;
    HttpCallback<BaseRes<AttentionContentBean>> saveHttp;
    public int stationId;
    public int stationType;

    @Override // com.androidx.p013lv.base.p015ui.BaseActivity
    public int setLayout() {
        return C1069R.C1074layout.activity_star;
    }

    /* access modifiers changed from: protected */
    @Override // com.androidx.p013lv.base.p015ui.BaseActivity
    public void initView() {
        super.initView();
        EventBus.getDefault().register(this);
        ((ActivityStarBinding) this.binding).tvTitle.setText(this.name);
        ((ActivityStarBinding) this.binding).refresh.setOnRefreshListener(this);
        ((ActivityStarBinding) this.binding).refresh.setOnLoadMoreListener(this);
        ((ActivityStarBinding) this.binding).tvBack.setOnClickListener(new View.OnClickListener() {
            /* class com.androidx.p013lv.invention.activity.StarActivity.View$OnClickListenerC10891 */

            public void onClick(View view) {
                StarActivity.this.finish();
            }
        });
        ((ActivityStarBinding) this.binding).recycler.setLayoutManager(new LinearLayoutManager(this));
        this.adapter = new AdapterStar();
        ((ActivityStarBinding) this.binding).recycler.setAdapter(this.adapter);
        this.adapter.setItemListener(this);
        ((ActivityStarBinding) this.binding).statusLayout.setOnRetryListener(new View.OnClickListener() {
            /* class com.androidx.p013lv.invention.activity.StarActivity.View$OnClickListenerC10902 */

            public void onClick(View view) {
                StarActivity.this.lastId = 0;
                StarActivity.this.getInfo();
            }
        });
        getInfo();
    }

    /* access modifiers changed from: package-private */
    public void getInfo() {
        if (this.lastId == 0) {
            AdapterStar adapterStar = this.adapter;
            if (!(adapterStar == null || adapterStar.getData() == null || this.adapter.getData().size() <= 0)) {
                this.adapter.clear();
            }
            if (!NetUtil.isNetworkAvailable()) {
                ((ActivityStarBinding) this.binding).statusLayout.showNoNet();
                return;
            }
            ((ActivityStarBinding) this.binding).statusLayout.showLoading();
        }
        HttpUtils.getInsatance().get(UrlManager.getInsatance().queryContentMore(this.stationId, this.lastId, 30, this.stationType), new HttpCallback<BaseRes<StarBean>>(this.HTTP_TAG) {
            /* class com.androidx.p013lv.invention.activity.StarActivity.C10913 */

            public void onLvSuccess(BaseRes<StarBean> baseRes) {
                ((ActivityStarBinding) StarActivity.this.binding).statusLayout.hideLoading();
                ((ActivityStarBinding) StarActivity.this.binding).refresh.finishRefresh();
                ((ActivityStarBinding) StarActivity.this.binding).refresh.finishLoadMore();
                if (baseRes.getCode() == 200) {
                    if (baseRes.getData() != null && baseRes.getData().getList() != null && baseRes.getData().getList().size() > 0) {
                        StarActivity.this.adapter.setDomain(baseRes.getData().getDomain());
                        if (StarActivity.this.lastId == 0) {
                            StarActivity.this.adapter.setData(baseRes.getData().getList());
                            ((ActivityStarBinding) StarActivity.this.binding).refresh.resetNoMoreData();
                            return;
                        }
                        StarActivity.this.adapter.setDatasInEnd(baseRes.getData().getList());
                    } else if (StarActivity.this.lastId == 0) {
                        ((ActivityStarBinding) StarActivity.this.binding).statusLayout.showEmpty();
                    } else {
                        ((ActivityStarBinding) StarActivity.this.binding).refresh.finishLoadMoreWithNoMoreData();
                    }
                } else if (StarActivity.this.lastId == 0) {
                    ((ActivityStarBinding) StarActivity.this.binding).statusLayout.showError();
                } else {
                    ToastUtils.getInstance().showWeak(baseRes.getMsg());
                }
            }
        });
    }

    @Override // com.scwang.smartrefresh.layout.listener.OnLoadMoreListener
    public void onLoadMore(RefreshLayout refreshLayout) {
        InventionThreeBean inventionThreeBean = (InventionThreeBean) this.adapter.getLastDataInPosition();
        if (inventionThreeBean == null) {
            ((ActivityStarBinding) this.binding).refresh.finishLoadMore();
            ((ActivityStarBinding) this.binding).refresh.finishLoadMoreWithNoMoreData();
            return;
        }
        this.lastId = inventionThreeBean.getSortNum();
        getInfo();
    }

    @Override // com.scwang.smartrefresh.layout.listener.OnRefreshListener
    public void onRefresh(RefreshLayout refreshLayout) {
        this.lastId = 0;
        getInfo();
    }

    /* access modifiers changed from: protected */
    @Override // androidx.appcompat.app.AppCompatActivity, androidx.fragment.app.FragmentActivity, com.androidx.p013lv.base.p015ui.BaseActivity
    public void onDestroy() {
        super.onDestroy();
        HttpUtils.getInsatance().cancelTag(this.HTTP_TAG);
        HttpUtils.getInsatance().cancelTag(this.HTTP_SAVE_TAG);
        HttpUtils.getInsatance().cancelTag(this.HTTP_CANCEL_TAG);
        EventBus.getDefault().unregister(this);
    }

    /* access modifiers changed from: protected */
    @Override // com.androidx.p013lv.base.p015ui.BaseActivity
    public void initImmersionBar() {
        super.initImmersionBar();
        ImmersionBar.with(this).titleBar(((ActivityStarBinding) this.binding).toolbar).init();
    }

    @Override // com.androidx.p013lv.base.listener.ItemClickListener
    public void onItemClick(View view, int i) {
        if (!isOnClick()) {
            if (view.getId() == C1069R.C1072id.iv_cover || view.getId() == C1069R.C1072id.btn_sum) {
                ARouter.getInstance().build(Constance.STAR_INFO_ACTIVITY).withInt("type", ((InventionThreeBean) this.adapter.getDataInPosition(i)).getContentId()).withString(Key.TXT, "返回").navigation();
            } else if (view.getId() == C1069R.C1072id.iv_attention) {
                InventionThreeBean inventionThreeBean = (InventionThreeBean) this.adapter.getDataInPosition(i);
                this.bean = inventionThreeBean;
                this.index = i;
                if (inventionThreeBean.isAttention()) {
                    HttpAttention.getInstance().cancelAttention(this.bean.getContentId(), cancelHttp());
                } else {
                    HttpAttention.getInstance().saveAttention(this.bean.getContentId(), saveHttp());
                }
            }
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onGetMessage(AttentionEvent attentionEvent) {
        AdapterStar adapterStar = this.adapter;
        if (!(adapterStar == null || adapterStar.getData() == null || this.adapter.getData().size() == 0)) {
            for (int i = 0; i < this.adapter.getItemCount(); i++) {
                InventionThreeBean inventionThreeBean = (InventionThreeBean) this.adapter.getDataInPosition(i);
                if (attentionEvent.getContentId() == inventionThreeBean.getContentId()) {
                    inventionThreeBean.setAttention(attentionEvent.isAttention());
                    this.adapter.notifyItemChanged(i);
                    return;
                }
            }
        }
    }

    public HttpCallback<BaseRes<AttentionContentBean>> cancelHttp() {
        if (this.cancelHttp == null) {
            this.cancelHttp = new HttpCallback<BaseRes<AttentionContentBean>>(this.HTTP_CANCEL_TAG, this) {
                /* class com.androidx.p013lv.invention.activity.StarActivity.C10924 */

                public void onLvSuccess(BaseRes<AttentionContentBean> baseRes) {
                    if (baseRes.getCode() == 200) {
                        StarActivity.this.bean.setAttention(false);
                        StarActivity.this.adapter.notifyItemChanged(StarActivity.this.index);
                        return;
                    }
                    ToastUtils.getInstance().showWeak(baseRes.getMsg());
                }
            };
        }
        return this.cancelHttp;
    }

    public HttpCallback<BaseRes<AttentionContentBean>> saveHttp() {
        if (this.saveHttp == null) {
            this.saveHttp = new HttpCallback<BaseRes<AttentionContentBean>>(this.HTTP_SAVE_TAG, this) {
                /* class com.androidx.p013lv.invention.activity.StarActivity.C10935 */

                public void onLvSuccess(BaseRes<AttentionContentBean> baseRes) {
                    if (baseRes.getCode() != 200) {
                        return;
                    }
                    if (baseRes.getCode() == 200) {
                        StarActivity.this.bean.setAttention(true);
                        StarActivity.this.adapter.notifyItemChanged(StarActivity.this.index);
                        return;
                    }
                    ToastUtils.getInstance().showWeak(baseRes.getMsg());
                }
            };
        }
        return this.saveHttp;
    }
}
